home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / SUB_ARCT / LIB / DISPLAY_.JAV < prev    next >
Encoding:
Text File  |  1996-10-04  |  4.8 KB  |  169 lines

  1. package sub_arctic.lib;
  2.  
  3. import sub_arctic.input.display_help;
  4. import sub_arctic.input.event;
  5. import sub_arctic.constraints.std_function;
  6. import java.awt.Point;
  7.  
  8. /**
  9.  * This is a general purpose container which can take any object
  10.  * as its only child. Once an object is put in this container, the
  11.  * container can generate a "display help" string onto the
  12.  * top of the containing interface. This display help string is
  13.  * generated after the pointer has been stationary on this object
  14.  * for a few seconds (i.e. when we get told mouse_stationary())
  15.  *
  16.  * @author Ian Smith
  17.  */
  18. public class display_help_container 
  19.   extends base_parent_interactor implements display_help {
  20.  
  21.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  22.  
  23.   /**
  24.    * The help text
  25.    */
  26.   protected String _text;
  27.  
  28.   /**
  29.    * Retrieve the current help text.
  30.    * @return String the current help text string
  31.    */
  32.   public String text() { return _text;}
  33.  
  34.   /**
  35.    * Set the current help text.
  36.    * @param String t the new text
  37.    */
  38.   public void set_text(String t) { _text=t;}
  39.  
  40.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  41.  
  42.   /**
  43.    * Construct a display help container given an interactor and
  44.    * a string.
  45.    * @param interactor i the interactor to display the help for
  46.    * @param String text the help text to display (should be short)
  47.    */ 
  48.   public display_help_container(interactor i, String text) {
  49.     super(0,0,10,10); /* temporary */
  50.     _text=text;
  51.     set_w_constraint(std_function.offset(FIRST_CHILD.W(),0));
  52.     set_h_constraint(std_function.offset(FIRST_CHILD.H(), 0));
  53.     setup_for_fixed_children(1);
  54.     set_child(0,i);
  55.   }
  56.  
  57.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  58.  
  59.   /**
  60.    * This method is called when the pointer enters our area and
  61.    * when no other agent has dispatched the event. We do nothing here
  62.    * since we are planning to display help text.
  63.    * 
  64.    * @param event  evt       the event to dispatch.
  65.    * @param Object user_info the object you passed to the pick_collector at 
  66.    *                          pick_time.
  67.    * @return boolean return true if you dispatched this event.
  68.    */
  69.   public boolean mouse_enter(event evt, Object user_info) {
  70.     return true;
  71.   }
  72.  
  73.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  74.  
  75.   /**
  76.    * This method is called when the pointer leaves our area. This method
  77.    * does nothing, we are only using the display help interface.
  78.    *
  79.    * @param event evt the event to dispatch
  80.    */
  81.   public void mouse_exit(event evt) {
  82.   }
  83.  
  84.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  85.  
  86.   /**
  87.    * This is where we stash the top level's extra child while its
  88.    * up.
  89.    */
  90.   protected label help_text;
  91.  
  92.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  93.  
  94.   /**
  95.    * This method is called to inform the object that the help text
  96.    * should be displayed now. 
  97.    */
  98.   public void help_open() {
  99.     top_level top=get_top_level();
  100.     Point global;
  101.     int x;
  102.  
  103.     /* there is no top level, give up */
  104.     if (top==null) {
  105.       return;
  106.     }
  107.  
  108.     /* normal case: convert our 0,0 to the top_levels coord system */
  109.     global=local_to_global(0,0);
  110.     
  111.     /*make the label we want */
  112.     help_text=new label(text());
  113.     help_text.set_boxed(true);
  114.     help_text.set_opaque(true);
  115.     
  116.     /* set the x coordinate... */
  117.     x=global.x;
  118.     /* is the string just too big?*/
  119.     if (help_text.w()>top.w()) {
  120.       /* it is, so just do what you can... */
  121.       x=0;
  122.     } else {
  123.       /* it fits, do we need to right justify?*/
  124.       if (x+help_text.w()>top.w()) {
  125.     x=top.w()-help_text.w();
  126.       }
  127.     }
  128.     
  129.     /* set the coords */
  130.     help_text.set_x(x);
  131.     help_text.set_y(global.y+h());
  132.     top.add_child(help_text);
  133.   }
  134.  
  135.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  136.  
  137.   /**
  138.    * This method is called to inform the object that the help text
  139.    * should not be displayed any longer. 
  140.    *
  141.    * @param event evt the event the "caused" this input.
  142.    */
  143.   public void help_close(event evt) {
  144.     top_level top=get_top_level();
  145.     if (top!=null) {
  146.       top.remove_child(help_text);
  147.     }
  148.   }
  149.  
  150.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  151. }
  152.  
  153. /*=========================== COPYRIGHT NOTICE ===========================
  154.  
  155. This file is part of the subArctic user interface toolkit.
  156.  
  157. Copyright (c) 1996 Scott Hudson and Ian Smith
  158. All rights reserved.
  159.  
  160. The subArctic system is freely available for most uses under the terms
  161. and conditions described in 
  162.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  163. and appearing in full in the lib/interactor.java source file.
  164.  
  165. The current release and additional information about this software can be 
  166. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  167.  
  168. ========================================================================*/
  169.